$(document).ready(function () {
  let page = {
    init() {
      this.getNews();
    },
    news: [],
    asyNews(data) {
      let html = "";
      data.map((item) => {
        html += `<div class="news-info flex">
        <div class="time text-center">
          <div class="time-top">${item.date}</div>
          <div class="color-19BC9B">${item.year}</div>
        </div>
        <div class="info-content">
          <p class="color-333">${item.title}</p>
          <p class="ft-14">${item.summary}</p>
          <p  class="ft-14 color-19BC9B new-href">查看详情>></p>
        </div>
      </div>`;
      });
      $(".news-list").html(html);

      $(".new-href").click(function () {
        var id = $(".new-href").index(this);
        localStorage.setItem("newDetail", page.news[id].content);
        location.href = "./newDetail.html";
      });
    },
    getNews(type = "") {
      $.ajax({
        url:
          "http://60.190.238.5:8080/advance/huijiFlexible/flexInformation/getAllList",
        data: { type: type }, // 0政策 1新闻  2法规
        success(res) {
          let data = res.data;
          data.map((item) => {
            item.year = item.publishTime.slice(0, 4);
            item.date = item.publishTime.slice(5, 10);
          });
          page.news = data;
          page.asyNews(data);
        },
      });
    },
  };
  page.init()
  $(".news-nav li").click(function () {
    var id = $(this).index();
    let type = $(this).data("type");
    $(this).addClass("active").siblings("li").removeClass("active");
    page.getNews(type);
  });
});
